using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations.Schema;

namespace Zhaoxi.Zhihu.SharedKerel.Domain;

public abstract class BaseEntity<TId>:IEntity<TId>
{
    public TId Id { get; set; } = default!;
    
    private readonly List<BaseEvent> _domainEvent = new ();
    [NotMapped]
    public ReadOnlyCollection<BaseEvent> DomainEvent => _domainEvent.AsReadOnly();

    public void AddDomainEvent(BaseEvent domainEvent)
    {
        _domainEvent.Add(domainEvent);
    }

    public void RemoveDomainEvent(BaseEvent domainEvent)
    {
        _domainEvent.Remove(domainEvent);
    }

    public void ClearDomainEvents()
    {
        _domainEvent.Clear();
    }
}